// Lightning
// By: Brandon Fogerty
// bfogerty at gmail dot com 
// xdpixel.com


#ifdef GL_ES
precision mediump float;
#endif

//uniform float time;
//uniform vec2 mouse;
//uniform vec2 resolution;

vec2 resolution = vec2(1136,768);

//#define Resolution				resolution
#define time					CC_Time[2]

float Hash( vec2 p)
{
     vec3 p2 = vec3(p.xy,2.0);
    return fract(sin(dot(p2,vec3(207.1,200.7, 2.4)))*0.5453123);
}

float noise(in vec2 p)
{
    vec2 i = floor(p);
     vec2 f = fract(p);
     f *= f * (3.0-2.0*f);
    return mix(mix(Hash(i + vec2(0.,0.)), Hash(i + vec2(1.,0.)),f.x),
               mix(Hash(i + vec2(0.,1.)), Hash(i + vec2(1.,1.)),f.x),
               f.y);
}

float fbm(vec2 p)
{
     float v = 0.0;
     v += noise(p*1.0) * .5;
     v += noise(p*2.)  * .25;
     v += noise(p*4.)  * .125;
     return v;
}

vec2 sinvec2(vec2 p)
{
	float t = 10;
	float reY = sin(p.x*t);
	vec2 re = vec2(p.x,reY);
	return vec2(p.x,re.y*noise(re));
} 

vec2 sinvec2plus(vec2 p)
{
	float t = 0.05;
	vec2 re1 = sinvec2(p);
	float reY = t*sin(p.x);
	vec2 re = vec2(p.x,reY);
	return re + re1;
}

void main( void ) 
{

	vec2 uv = ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0;
	uv.y *= resolution.x/resolution.y;

	vec3 finalColor = vec3( 0.0 );
	float amp = 100.0;
	float period = 2.0;
	float t = abs( 1.0 / (sin(uv.y + fbm( sinvec2plus(uv) + time * period )) * amp) );
		
	finalColor +=  t * vec3( 2.9, 1.5, .25 );
	
	//gl_FragColor = vec4( finalColor, 1.0 );

	if (finalColor.x <= 1.0 && finalColor.y <= 1.0 && finalColor.z <= 1.0)
	{
		gl_FragColor = vec4( finalColor, 0.0 );
	}
	else
	{
		gl_FragColor = vec4( finalColor, 1.0 );
	}

}